package com.tjsinfo.tjsoa.vote.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.vote.bo.ITVoteHeadBO;
import com.tjsinfo.tjsoa.vote.vo.TVoteHead;;;

public class HeadAddAction extends Action {
	
	private ITVoteHeadBO headBo;
	
	public void setHeadBo(ITVoteHeadBO headBo) {
		this.headBo = headBo;
	}

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {
			TVoteHead tvh = new TVoteHead();
			tvh.setName(request.getParameter("name"));
			tvh.setYearTime(request.getParameter("yearTime"));
			tvh.setRemark(request.getParameter("remark"));
			tvh.setStatus(0);
			tvh.setVote(request.getParameter("voteId"));
			tvh.setVoteName(request.getParameter("voteName"));
			Integer userId = ToolKit.getSessionUser(request).getUser_id();
			tvh.setUserId(userId.toString());
			tvh.setUserName(ToolKit.getSessionUser(request).getUsername());
			headBo.save(tvh);
			request.setAttribute("linkurl", "tjsinfo/tjsoa/vote/headList.do");
			request.setAttribute("message", "vote.headAdd.message");
			return mapping.findForward("success");
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("failed");
		}
	}
}
